package org.gwt.pluginframework.desktop.client;

import org.gwt.pluginframework.common.Plugin;

import com.extjs.gxt.ui.client.event.BaseEvent;
import com.extjs.gxt.ui.client.event.Events;
import com.extjs.gxt.ui.client.event.Listener;
import com.extjs.gxt.ui.client.widget.TabItem;
import com.extjs.gxt.ui.client.widget.TabPanel;
import com.google.gwt.core.client.Scheduler;
import com.google.gwt.core.client.impl.SchedulerImpl;
import com.google.gwt.user.client.ui.Label;

public class FormC extends Plugin {
	private static final long serialVersionUID = -2554649514156147440L;

	protected TabPanel main;

	protected TabItem item;

	public FormC(String name) {
		super();
		
		manifest.setName(manifest.getName() + "_" + name);
	}
	
	public void setupManifest() {
		manifest.setName("FormC");
		manifest.setVersion("1.0");
	}
	
	@Override
	public void onStart() {
		item = new TabItem();
		item.setText(manifest.getName());
		item.add(new Label("My item " + manifest.getName()));
		item.setClosable(true);
		item.addListener(Events.Close, new Listener<BaseEvent>() {
			public void handleEvent(BaseEvent be) {
				Scheduler scheduler = new SchedulerImpl();
				scheduler.scheduleDeferred(new Scheduler.ScheduledCommand() {
					public void execute() {
						stop();
						destroy();
					}
				});
			}
		});
	}
	
	public TabItem getTabItem() {
		return item;
	}
}
